capture log close
********************************************************************************
*                   do-file to run conditional logit models                    *
*            A replication of Ochsenfeld (2016), Patzina & Toussaint           *
********************************************************************************

version 13
clear
set more off

 
*Definition of the global path for saving datasets and logfiles
global project "Z:\Projects\p000165_DUA_3627\Gender Segregation"

cd "${project}"
log using analysis_pt, replace

use "${project}\data_choice_long_w7.dta"

*** Globals ***
global maineffects = "fach1-fach7 fach9-fach23"  /*refcat: econ sciences*/
global modnr = 17  /*number of models to be stored in matrix */

*for analyses by pscores
*drop if pscore < 0.8161476 //only individuals with a study prop. equal to or above the median
*drop if pscore >= 0.8161476 //only individuals with a study prop. below the median
*drop if pscore > 0.7454649 //only individuals with a study prop. equal to or below the 25% percentile
*drop if (pscore <= 0.7454649 | pscore > 0.8161476) //only individuals with a study prop. between 25% and 50% percentile
*drop if (pscore < 0.8161476 | pscore >= 0.8699815 ) //only individuals with a study prop. between 50% and 75% percentile
*drop if pscore < 0.8699815 // only individuals with a study prop. above the 75% percentile

****************************************
*** multivariate analysis of effects ***
****************************************

clogit choice $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper ///
mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
est sto a_m1
esttab a_m1

clogit choice $maineffects std_mathintxdoer std_carexdoer std_mathintxthinker std_carexthinker std_mathintxcreator std_carexcreator std_mathintxhelper std_carexhelper ///
std_mathintxpersuader std_carexpersuader std_mathintxorganizer std_carexorganizer std_apfmeltxfrau std_apfmpeerxfrau std_mathintxleist_md std_intercptxbread std_hrsworkxflexi  [pw=w_t13_std], group(id_ind) or
est sto a_m2
esttab a_m2


***************************************
*** min max decomposition ***
***************************************

*reference models: baseline and saturated:
qui clogit choice pfemale2xfrau $maineffects [pw=w_t13_std], group(id_ind) or
matrix A=(e(b))

clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix B=e(b)

* 1 - interest:doer
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer [pw=w_t13_std], group(id_ind) or
matrix E1max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E1min=e(b)


* 2 - interest: thinker
qui clogit choice pfemale2xfrau $maineffects mathintxthinker carexthinker [pw=w_t13_std], group(id_ind) or
matrix E2max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E2min=e(b)


* 3 - interest: creator
qui clogit choice pfemale2xfrau $maineffects mathintxcreator carexcreator [pw=w_t13_std], group(id_ind) or
matrix E3max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E3min=e(b)


* 4 - interest: helper
qui clogit choice pfemale2xfrau $maineffects mathintxhelper carexhelper [pw=w_t13_std], group(id_ind) or
matrix E4max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E4min=e(b)


* 5 - interest: persuader
qui clogit choice pfemale2xfrau $maineffects mathintxpersuader carexpersuader [pw=w_t13_std], group(id_ind) or
matrix E5max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper ///
mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E5min=e(b)


* 6 - interest: organizer
qui clogit choice pfemale2xfrau $maineffects mathintxorganizer carexorganizer [pw=w_t13_std], group(id_ind) or
matrix E6max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E6min=e(b)


* 7 - essentialism: internalized total
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer [pw=w_t13_std], group(id_ind) or
matrix E7max=e(b)

qui clogit choice pfemale2xfrau $maineffects apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E7min=e(b)


* 8 - gender norms: parents
qui clogit choice pfemale2xfrau $maineffects apfmeltxfrau [pw=w_t13_std], group(id_ind) or
	matrix E8max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E8min = e(b)	

* 9 - gender norms: peers
qui clogit choice pfemale2xfrau $maineffects apfmpeerxfrau [pw=w_t13_std], group(id_ind) or
	matrix E9max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E9min = e(b)

* 10 - gender norms: total	
qui clogit choice pfemale2xfrau $maineffects apfmeltxfrau apfmpeerxfrau [pw=w_t13_std], group(id_ind) or
	matrix E10max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E10min = e(b)
	
* 11 - education: relative math grades
qui clogit choice pfemale2xfrau $maineffects mathintxleist_md [pw=w_t13_std], group(id_ind) or
matrix E11max=e(b)

qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E11min=e(b)

* 12 - essentialism: total	
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md [pw=w_t13_std], group(id_ind) or
	matrix E12max = e(b)
qui clogit choice pfemale2xfrau $maineffects intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E12min = e(b)
	
* 13 - separate spheres: bread
qui clogit choice pfemale2xfrau $maineffects intercptxbread [pw=w_t13_std], group(id_ind) or
	matrix E13max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E13min = e(b)	
		
* 14 - separate spheres: overwork
qui clogit choice pfemale2xfrau $maineffects hrsworkxflexi [pw=w_t13_std], group(id_ind) or
	matrix E14max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E14min = e(b)
	
* 15  - separate spheres: total	
qui clogit choice pfemale2xfrau $maineffects intercptxbread	hrsworkxflexi [pw=w_t13_std], group(id_ind) or
	matrix E15max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E15min = e(b)

* 16 - discrimination
qui clogit choice pfemale2xfrau $maineffects fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	matrix E16max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi [pw=w_t13_std], group(id_ind) or
	matrix E16min = e(b)
	
* 17 - total
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader ///
carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread hrsworkxflexi fdiscrimxfrau [pw=w_t13_std], group(id_ind) or
matrix E17max=e(b)

qui clogit choice pfemale2xfrau $maineffects [pw=w_t13_std], group(id_ind) or
matrix E17min=e(b)


/* results matrix for min max decomposition
   rows:models
   columns:
   1 - rownumber
   2 - baseline coefficient pfemale2xfrau
   3 - pfemale2xfrau when adding var
   4 - max% explained for horizontal segregation
   5 - saturated coefficient pfemale2xfrau
   6 - pfemale2xfrau when dropping var
   7 - min% explained for hotizontal segregation
 */
 
 matrix decomphor = J($modnr , 7, .)
 
 matrix rownames decomphor= 1_doer 2_thinker 3_creator 4_helper 5_persuader 6_organizer 7_int_total 8_norms_elt 9_norms_peer ///
	10_norms_total 11_mdnoten 12_essent_total 13_bread 14_hrswork 15_sepsphe_total 16_discrimination 17_total
 matrix colnames decomphor= 1_rownr 2_base_hori 3_coef_add_hori 4_maxexpl_hori 5_satu_hori 6_coef_drop_hori 7_minexpl_hori
 
 
 ***compute percentage explained (as in Morgan et al 2013)
 
forvalues i=1/$modnr{
	matrix decomphor[`i',1]=`i'
	matrix decomphor[`i',2]=exp(A[1,1])
	matrix decomphor[`i',3]=exp(E`i'max[1,1])
	matrix decomphor[`i',4]=((decomphor[`i',2]-1)-(decomphor[`i',3]-1))/(decomphor[`i',2]-1)
	matrix decomphor[`i',5]=exp(B[1,1])
	matrix decomphor[`i',6]=exp(E`i'min[1,1])
	matrix decomphor[`i',7]=-1*((decomphor[`i',5]-1)-(decomphor[`i',6]-1))/(decomphor[`i',2]-1)
	}

matrix list decomphor, format(%10.4f)


***end of dofile***
log close
exit, clear
